﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using Entity;

namespace DAL
{
    public class SupportDAL : SqlDataProvider
    {
        #region[Support_GetById]
        public List<Support> Support_GetById(string Id)
        {
            List<Entity.Support> list = new List<Entity.Support>();
            using (SqlCommand dbCmd = new SqlCommand("sp_Support_GetById", GetConnection()))
            {

                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@Id", Id));
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(Support.SupportIDataReader(dr));
                    }
                }
                dr.Close();

            }
            return list;
        }
        #endregion
        #region[Support_GetByTop]
        public List<Support> Support_GetByTop(string Top, string Where, string Order)
        {
            List<Entity.Support> list = new List<Entity.Support>();
            using (SqlCommand dbCmd = new SqlCommand("sp_Support_GetByTop", GetConnection()))
            {

                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@Top", Top));
                dbCmd.Parameters.Add(new SqlParameter("@Where", Where));
                dbCmd.Parameters.Add(new SqlParameter("@Order", Order));
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(Support.SupportIDataReader(dr));
                    }
                }
                dr.Close();

            }
            return list;
        }
        #endregion
        #region[Support_GetByAll]
        public List<Support> Support_GetByAll(string Lang)
        {
            List<Entity.Support> list = new List<Entity.Support>();
            using (SqlCommand dbCmd = new SqlCommand("sp_Support_GetByAll", GetConnection()))
            {

                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@Lang", Lang));
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(Support.SupportIDataReader(dr));
                    }
                }
                dr.Close();

            }
            return list;
        }
        #endregion
        #region[Support_Insert]
        public bool Support_Insert(Support data)
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_Support_Insert", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@Name", data.Name));
                dbCmd.Parameters.Add(new SqlParameter("@Tel", data.Tel));
                dbCmd.Parameters.Add(new SqlParameter("@Type", data.Type));
                dbCmd.Parameters.Add(new SqlParameter("@Nick", data.Nick));
                dbCmd.Parameters.Add(new SqlParameter("@Ord", data.Ord));
                dbCmd.Parameters.Add(new SqlParameter("@Active", data.Active));
                dbCmd.Parameters.Add(new SqlParameter("@PageId", data.PageId == "" || data.PageId == "0" ? DBNull.Value : (object)data.PageId));
                dbCmd.Parameters.Add(new SqlParameter("@Lang", data.Lang));
                dbCmd.ExecuteNonQuery();
            }
            //Clear cache
            System.Web.HttpContext.Current.Cache.Remove("Support");
            return true;
        }
        #endregion
        #region[Support_Update]
        public bool Support_Update(Support data)
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_Support_Update", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@Id", data.Id));
                dbCmd.Parameters.Add(new SqlParameter("@Name", data.Name));
                dbCmd.Parameters.Add(new SqlParameter("@Tel", data.Tel));
                dbCmd.Parameters.Add(new SqlParameter("@Type", data.Type));
                dbCmd.Parameters.Add(new SqlParameter("@Nick", data.Nick));
                dbCmd.Parameters.Add(new SqlParameter("@Ord", data.Ord));
                dbCmd.Parameters.Add(new SqlParameter("@Active", data.Active));
                dbCmd.Parameters.Add(new SqlParameter("@PageId", data.PageId == "" || data.PageId == "0" ? DBNull.Value : (object)data.PageId));
                dbCmd.Parameters.Add(new SqlParameter("@Lang", data.Lang));
                dbCmd.ExecuteNonQuery();
            }
            //Clear cache
            System.Web.HttpContext.Current.Cache.Remove("Support");
            return true;
        }
        #endregion
        #region[Support_Delete]
        public bool Support_Delete(string Id)
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_Support_Delete", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@Id", Id));
                dbCmd.ExecuteNonQuery();
            }
            //Clear cache
            System.Web.HttpContext.Current.Cache.Remove("Support");
            return true;
        }
        #endregion

    }
}
